import 'package:flutter/material.dart';
import "package:get/get.dart";

import '../../common.dart';

class EditInfo extends StatelessWidget {
  
  RxList listData =[].obs;
  RxBool istrue = false.obs;

  @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      getData(url: '/bbs/wiki').then((res) {
        if (res != null) {
          listData.value=res;
        }
      });
    });

    return Scaffold(
        appBar: AppBar(
            centerTitle: true,
            backgroundColor: Color(0xffffffff),
            leadingWidth: 40,
            leading: buildBackButton(context),
            title:wText(text: '编辑百科',size: 18)),
        body: Column(
          children: [
            Expanded(
              child: 
              Obx(()=>
              ListView.builder(
                itemCount:listData.length,
                padding: EdgeInsets.symmetric(horizontal: 15),
                itemBuilder:(context, index) {
                return  Container(
                      margin: EdgeInsets.symmetric(vertical: 5),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(5),
                        color: Color(0xfff5f5f5),
                      ),
                      padding:
                          EdgeInsets.symmetric(horizontal: 15, vertical: 15),
                      child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '${listData[index]['title']}',
                                style: TextStyle(fontSize: 15),
                              ),
                              GestureDetector(
                                 onTap: () async {
                                     final shouldRefresh = await toNamed('/user/personal/add_module',{'title': '${listData[index]['title']}','text':'${listData[index]['text']}','type':'1','id':'${listData[index]['id']}'});
                                    if (shouldRefresh) {
                                      istrue.value=shouldRefresh;
                                   getData(url: '/bbs/wiki').then((res) {
                                      if (res != null) {
                                        listData.value=res;
                                      }
                                    });
                }
                                    },
                                child: Image.asset(
                                  'static/images/bianji.png',
                                  width: 13,
                                  fit: BoxFit.fitWidth,
                                ),
                              )
                            ],
                          ),
                          SizedBox(
                            height: 5,
                          ),
                          Align(
                            alignment: Alignment.topLeft,
                            child: Text(
                              '${listData[index]['text']}',
                              style: TextStyle(
                                  fontSize: 12,
                                  color: Color(0XFF999999),
                                  height: 1.6),
                            ),
                          )
                        ],
                      ));
                },
              ),
              ),

            ),
            SizedBox(
              height: 15,
            ),
            GestureDetector(
              onTap: () async {
                final shouldRefresh =
                    await toNamed('/user/personal/add_module?type=0') ?? false;
                if (shouldRefresh) {
                  istrue.value=shouldRefresh;
                 getData(url: '/bbs/wiki').then((res) {
                    if (res != null) {
                      listData.value=res;
                    }
                  });
                }
              },
              child: Container(
                margin: EdgeInsets.symmetric(horizontal: 30),
                alignment: Alignment.center,
                height: 40,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular((50)),
                  gradient: LinearGradient(
                    colors: [
                      Color(0xff2189E7),
                      Color(0xffBF67F8),
                    ], // 定义颜色列表
                    begin: Alignment.topLeft, // 渐变开始的位置
                    end: Alignment.bottomRight, // 渐变结束的位置
                  ),
                ),
                child: Text(
                  '添加模块',
                  style: TextStyle(fontSize: 16, color: Color(0XFFFFFFFF)),
                ),
              ),
            ),
            SizedBox(
              height: 15,
            ),
          ],
        )
        // Padding(
        //   padding: EdgeInsets.symmetric(horizontal: 15),
        //   child:
        // ),
        );
  }
}
